package com.doit.demo03;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class test_Collections {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(12);
        list.add(52);
        list.add(42);
        list.add(22);
        Collections.sort(list);//按照升序排序
        System.out.println(list);

        List<String>list2 = new ArrayList<>();
        list2.add("sd");
        list2.add("sa");
        list2.add("ad");
        list2.add("abd");
        Collections.sort(list2);//按照Ascii排序
        System.out.println(list2);
        System.out.println(Collections.binarySearch(list2, "sd"));

        System.out.println(Collections.binarySearch(list, 12));//二分查找
        Collections.shuffle(list);//打乱顺序
        System.out.println(list);

        System.out.println("--------------------");
        Collections.sort(list);
        System.out.println(list);
        Collections.sort(list, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        System.out.println(list);

    }
}
